const wxp = require('../../static/wx.promise').default
const _variable = require('../../static/variable')

let _wx = {}

/**
 * 检测某个setting是否授权过
 *
 * @param key
 * @returns {Promise<any>}
 */
_wx.checkSettingAuthed = function (key) {
  return new Promise(resolve => {
    wxp.getSetting().then(res => {
      let ret = res.authSetting[_variable.AuthSetting[key]]
      resolve(ret)
    })
  })
}

/**
 * showToast
 *
 * @param title
 * @param icon
 * @param d
 */
_wx.showToast = function (title, icon = 'none', d = {}) {
  let opt = {
    title,
    icon,
    duration: 2000,
  }
  wx.showToast({
    ...opt,
    ...d,
  })
}

export default _wx
